package com.nclg.exam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nclg.exam.dto.UserDto;
import com.nclg.exam.dto.UserPageDto;
import com.nclg.exam.mapper.AdminMapper;
import com.nclg.exam.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 模糊查询所有用户
     * @param dto
     * @return
     */
    @Override
    public PageInfo<UserPageDto> selectByPage(UserDto dto) {
        PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<UserPageDto> users = adminMapper.selectByPage(dto);
        return new PageInfo<>(users);
    }

    /**
     * 修改用户状态
     * @param uId
     * @param uStatus
     * @return
     */
    @Override
    public boolean updateStatus(Long uId, String uStatus) {
        return adminMapper.updateStatus(uId, uStatus) > 0 ? true : false;
    }

    /**
     * 修改用户权限
     * @param uId
     * @param uRole
     * @return
     */
    @Override
    public boolean updateRole(Long uId, String uRole) {
        return adminMapper.updateRole(uId, uRole) > 0 ? true : false;
    }

}
